﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace WiMoGF.Config
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Main : Window
    {
        public Main()
        {
            InitializeComponent();
        }

        private void lnkZuneExtensions_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Process.Start("http://www.microsoft.com/downloads/details.aspx?FamilyID=48f7ba37-8ba7-4d16-8873-0b7f83ef77f9&displaylang=en");
        }

        private void lnkGameStudio_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Process.Start("http://www.microsoft.com/downloads/details.aspx?familyid=80782277-D584-42D2-8024-893FCD9D3E82&displaylang=en");
        }

        private void lnkSilverlightTools_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Process.Start("http://silverlight.net/getstarted");
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            if(!(chkWindowsMobile.IsChecked.Value || chkSilverlight.IsChecked.Value || chkZuneHD.IsChecked.Value))
                MessageBox.Show("You must select at least one project type.");

            var ofd = new SaveFileDialog();
            ofd.FileName = "WiMoGF.sln";
            ofd.AddExtension = true;
            ofd.Filter = "Microsoft Visual Studio Solution Files | *.sln";
            ofd.ShowDialog();

            var projectName = Regex.Replace(ofd.SafeFileName, @"[^\w\.]", "");
            projectName = projectName.Replace(".sln", "");
            var directory = System.IO.Path.GetDirectoryName(ofd.FileName);
            projectName = projectName.TrimEnd('.').TrimStart('.');


            directory += String.Format(@"\{0}", projectName);
            if(!System.IO.Directory.Exists(directory))
                System.IO.Directory.CreateDirectory(directory);

            Process.Start(directory);

            Project.CreateProject(directory, projectName, chkWindowsMobile.IsChecked, chkSilverlight.IsChecked, chkZuneHD.IsChecked);

            this.Close();

        }

        private void btnWiMoSite_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Process.Start("http://www.WiMo-GF.net");
        }
    }
}
